package com.loveprogrammer.oss.common.uploader.useage;

import com.aliyun.oss.OSSClient;
import com.aliyun.oss.OSSClientBuilder;
import com.loveprogrammer.oss.common.uploader.FileUploader;
import com.loveprogrammer.oss.common.uploader.InputStreamUploader;
import com.loveprogrammer.oss.common.uploader.TimeStampPathBuilder;
import com.loveprogrammer.oss.common.uploader.UploadPathBuilder;
import com.loveprogrammer.oss.common.uploader.constant.FileType;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

/**
 * @Description: TODO
 * @author: colagy
 * @date: 2020-12-13 11:12
 */
public class AlicloudOssUploader {

    public static void fileUploader() {
        File file = new File("head_img.jpg");
        UploadPathBuilder uploadPathBuilder = new TimeStampPathBuilder().path("img").fileName("head_img").fileType(FileType.jpg);
        FileUploader fileUploader = new FileUploader(file, uploadPathBuilder);
    }

    public static void inputStreamUploader() throws FileNotFoundException {
        InputStream inputStream = new FileInputStream("head_img.jpg");
        UploadPathBuilder uploadPathBuilder = new TimeStampPathBuilder().path("img").fileName("head_img").fileType(FileType.jpg);
        InputStreamUploader inputStreamUploader = new InputStreamUploader(inputStream, uploadPathBuilder);

        OSSClient oss = (OSSClient) new OSSClientBuilder().build("", "", "");
        inputStreamUploader.upload(oss, "");
    }

    public static void main(String[] args) throws FileNotFoundException {
        fileUploader();
        inputStreamUploader();
    }
}
